﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using dotFitness.Domain.Tests.Stubs;

namespace dotFitness.Domain.Tests
{
    [TestClass]
    public class EntityBaseTests
    {
        [TestMethod]
        public void derived_entity_references_are_equal()
        {
            var e1 = new EntityStub();
            var e2 = e1;

            Assert.AreEqual(e1, e2);
        }

        [TestMethod]
        public void derived_entity_references_are_not_equal()
        {
            var e1 = new EntityStub();
            var e2 = new EntityStub();

            Assert.AreNotEqual(e1, e2);
        }

        [TestMethod]
        public void derived_entity_with_same_ids_are_equal()
        {
            var e1 = new EntityStub();
            var e2 = new EntityStub();

            e1.GetType().BaseType.GetProperty("Id").SetValue(e1, 1, null);
            e2.GetType().BaseType.GetProperty("Id").SetValue(e2, 1, null);

            Assert.AreEqual(e1, e2);
        }

        [TestMethod]
        public void derived_entity_with_different_ids_are_not_equal()
        {
            var e1 = new EntityStub();
            var e2 = new EntityStub();

            e1.GetType().BaseType.GetProperty("Id").SetValue(e1, 1, null);
            e2.GetType().BaseType.GetProperty("Id").SetValue(e2, 2, null);

            Assert.AreNotEqual(e1, e2);
        }

        [TestMethod]
        public void derived_entity_references_are_equal_using_equals_operator()
        {
            var e1 = new EntityStub();
            var e2 = e1;

            Assert.IsTrue(e1 == e2);
        }

        [TestMethod]
        public void derived_entity_references_are_not_equal_using_equals_operator()
        {
            var e1 = new EntityStub();
            var e2 = new EntityStub();

            Assert.IsFalse(e1 == e2);
        }

        [TestMethod]
        public void derived_entity_not_equal_using_equals_operator_when_right_side_is_null()
        {
            var e1 = new EntityStub();

            Assert.IsFalse(e1 == null);
        }

        [TestMethod]
        public void derived_entity_not_equal_using_equals_operator_when_left_side_is_null()
        {
            var e1 = new EntityStub();

            Assert.IsFalse(null == e1);
        }

        [TestMethod]
        public void derived_entity_is_transient()
        {
            var e1 = new EntityStub();

            Assert.IsTrue(e1.IsTransient);
        }

        [TestMethod]
        public void derived_entity_is_not_transient()
        {
            var e1 = new EntityStub();

            e1.GetType().BaseType.GetProperty("Id").SetValue(e1, 1, null);

            Assert.IsFalse(e1.IsTransient);
        }
    }
}
